package com.example.test.dialogfactory;

import com.example.test.dialogfactory.MainActivity42.Bean;
import easier.app.x.service.CommandService;
import easier.log.logger.Logger;
import easier.safe.gson.GsonFactory;

public class MainActivity42ServiceRemote extends CommandService {

    @Override
    protected void onCommandReceive( int what, Object bundle ) {

        super.onCommandReceive( what, bundle );

        if ( what == 0 ) {
            Logger.d( bundle.toString() );
        } else if ( what == 1 ) {
            Logger.d( ((Bean) bundle).value );
        }
    }

    @Override
    protected String toString( int command, Object object ) {

        if ( command == 0 ) {
            return object.toString();
        } else if ( command == 1 ) {
            return GsonFactory.getSingletonGson().toJson( object );
        }
        return super.toString( command, object );
    }

    @Override
    protected Object fromString( int command, String s ) {

        if ( command == 0 ) {
            return s;
        } else if ( command == 1 ) {
            return GsonFactory.getSingletonGson().fromJson( s, Bean.class );
        }

        return super.fromString( command, s );
    }
}
